#include<stdio.h>
#include<malloc.h>
#include<string.h>
typedef struct{
	char name[21];
	int num;
}student;
void QuickSort(student** arr, int low, int high);
int judge(student * s1,student * s2)
{
	return s1->num!=s2->num?s1->num<s2->num:strcmp(s1->name,s2->name)>0;
}
int main()
{
 	int n;
 	scanf("%d",&n);
 	student** person=(student** )malloc(sizeof(student* )*n);
 	for(student** i=person;i<person+n;i++)
 	{
 		*i=(student* )malloc(sizeof(student));
 		scanf("%s",(*i)->name);
 		scanf("%d",&((*i)->num));
	}
	QuickSort(person,0,n-1);
	for(student** i=person;i<person+n;i++)
	{
		printf("Name:%s\n",(*i)->name);
		printf("total:%d\n\n",(*i)->num);
	}
}
int judge(student * s1,student * s2);
void QuickSort(student** arr, int low, int high)
{
    if(low<high)
    {
        int i=low,j=high;
		student *k=arr[low];
        while (i<j)
        {
            while(i<j&&  judge(arr[j],k))
				j--;
            if(i<j)
				arr[i++]=arr[j];
            while(i<j&&  !judge(arr[i],k))
				i++;
            if(i<j)
				arr[j--]=arr[i];
        }
        arr[i]=k;
        QuickSort(arr,low, i-1);
        QuickSort(arr,i+1,high);
    }
}
